package com.jhy.review.leetcode;

public class code04_MaxDepth {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {
        }
        TreeNode(int val) {
            this.val = val;
        }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public static class returnTypeHeight{
        int hei;
        public returnTypeHeight(int hei) {
            this.hei = hei;
        }
    }
    public int maxDepth(TreeNode root) {
        returnTypeHeight returnTypeHeight = process(root);
        return returnTypeHeight.hei;
    }
    public  static  returnTypeHeight process(TreeNode head){
        if(head == null){
            return new returnTypeHeight(0);
        }
        returnTypeHeight leftData = process(head.left);
        returnTypeHeight rightData = process(head.right);
        int height = Math.max(rightData.hei,leftData.hei)+1;
        return new returnTypeHeight(height);
    }



    //方法2
    public int maxDepth02(TreeNode head){
        if(head == null){
            return 0;
        }else {
            return Math.max(maxDepth02(head.left),maxDepth02(head.right))+1;
        }


    }



}
